Skip to content

OpenConceptLab/ocl_issues#3092 OpenConceptLab/ocl_issues#3093 | Supplements and reserved code spaces in OCL's model, under FHIR's rules - #1104

Draft
paynejd wants to merge 7 commits into
fhir-452-b-codesfrom
fhir-452-c-core
Draft

paynejd wants to merge 7 commits into
fhir-452-b-codesfrom
fhir-452-c-core

Conversation

@paynejd

@paynejd paynejd commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

Branch fhir-452-c-core, base fhir-452-b-codes (#1094, which merges the storage PR #1103 through #1091). Code system supplements (OpenConceptLab/ocl_issues#3092) and reserved code spaces (OpenConceptLab/ocl_issues#3093) in OCL's own model, for OpenConceptLab/ocl_online#452. Not part of the Dec 1 run.

Everything here runs only under FHIR's rules (ExpansionEvaluation.fhir_rules), so API users see no change. The OCL API and FHIR share this one implementation: FHIR's operations read the merge and the expansions it builds, and only present them (#1105).

Size

Four commits (and two merges of its base's new heads), 17 files, +2,077/−26: 879 lines of code, 1,198 of tests.

What it does

Supplements (ef78eb20, OpenConceptLab/ocl_issues#3092)

  • Finding them (core/sources/supplements.py): a code system version's supplements are supplement sources found by its canonical URL (decision D1, through the storage PR's index) and by pins (D2: never HEAD; wildcards allowed). A supplement is identified by its canonical, whatever URL names it.
  • Which apply (ExpansionEvaluation.supplements_for): those a request names, then those a collection version declares (D10: Collection.declared_supplements), then those that apply by default. Stored default supplements wait on decisions D3 and D4, so only global ones a request carries apply by default. One version of each supplement: a pinned version, else the newest that applies and that the reader can see.
  • Not found (D9, refined): a named or declared supplement that's unknown, hidden, not a supplement, or that applies to none of the versions used raises one SupplementNotFound (require_applied). One applied only by default that the caller can't see is left out silently. Building an expansion never raises.
  • One merged view of a concept (D5, merge / ExpansionEvaluation.merged): names, descriptions and extras, each marked with the supplement that gave it, the code system's own first. Codes match as written, then as FHIR spells them, whatever form OCL stores them in.
  • Expansions record what they used (Expansion.supplements_used, record_supplements), for each code system version they used, including those reached through imports (supplement_bases).
  • Concepts: in a supplement source only, a concept may have no name, and a name or description may have no language (ANY_LANGUAGE) when the write allows it (ALLOWS_ANY_LANGUAGE); an API metadata edit keeps a supplement with no language as it is. Every other source keeps every rule.

Reserved code spaces, extension-codes supplements, and supplement properties in filters (74d03c82, OpenConceptLab/ocl_issues#3093)

  • core.sources.reserved_codes.locate: a code in one of a version's reserved code spaces (the whole code matching the pattern, on RE2; a pattern that doesn't compile reserves nothing), with its default display (the space's, else User-assigned), and its definition by the first extension-codes supplement in use that defines it. Only an extension-codes supplement defines codes, and only in its base's reserved spaces.
  • core.collections.reserved_members: the reserved codes an expansion holds that no concept defines (Expansion.reserved_codes): a code a reference lists; all of a version's, which it can't list (has_unlisted_members), for a reference to all of a code system. A filter, cascade or value set never selects one. Exclusions and versions follow member_versions; with versionsMatch true they rank with the concept members of the same code.
  • Filters on a supplement's property (CollectionReference.get_filter_supplements, apply_database_filter): a filter on a property that a supplement in use declares reads that supplement's values with the code system's own, as the merged concept has them.

What's in the FHIR PR instead

Reading order

  1. core/sources/supplements.py: finding and choosing supplements, and the merge.
  2. core/collections/evaluation.py: supplements_for, merged, require_applied, asks_supplements.
  3. core/collections/models.py: record_supplements and supplement_bases; then get_filter_supplements, apply_database_filter and the ReservedMembers hook in the build.
  4. core/sources/reserved_codes.py, then core/collections/reserved_members.py.
  5. core/concepts/constants.py, serializers.py, validators.py and core/sources/serializers.py: names with no language, and nameless supplement concepts.
  6. core/collections/imports.py: condition (5), an import evaluated again when a supplement applies to a version it used.
  7. Tests: core/sources/tests/tests_supplements.py, tests_reserved_codes.py, then core/collections/tests/tests_reserved_codes.py and tests_supplement_filters.py.

Decisions it follows

From OpenConceptLab/ocl_issues#3033: D1, D2, D5, D9 (refined: a hidden supplement named in a request gets the same not-found as an unknown one; one applied only by default is skipped silently) and D10. D3/D4 (who sets a stored code system's default supplements) and D6 to D8 (the OCL API's fields) are open, and nothing here decides them.

API users

Their expansions don't change. Everything that evaluates is behind fhir_rules; nothing reads EXPANSION_FHIR_RULES_TOGGLE for a source with no reserved code spaces; no API field sets or shows the new storage. Tests show it: an expansion an API user builds, OCL's own rules, a PUT that can't set the fields, and GET responses that don't show them.

One rule changes for every write, by design: in a supplement source, a concept may have no name. A supplement may add only properties or extensions to a code. Production has no supplement sources. Every other source keeps every rule.

An import's stored expansion is also evaluated again, under FHIR's rules, when a supplement applies to a source version it used (core.collections.imports, condition 5).

Tests

  • Full gate on 9adc6e66, as pr.yml runs it: pylint 10.00; 4,629 tests OK (2 skipped) and 822 search-index tests OK; coverage 97%.
  • New tests: core/sources/tests/tests_supplements.py, tests_reserved_codes.py, core/collections/tests/tests_reserved_codes.py, tests_supplement_filters.py, and the import guard's in tests_imports.py.

Review

The code had three Codex defect passes, a simplification review and later checks on its own branches before this split. On this PR, three more passes:

  • Fixed: an imported value set's stored expansion was read as it is although a supplement in play could change what its filters select. It's now evaluated again when a supplement applies to a source version it used (4514b61b, narrowed in c6778a34).
  • By design: a supplement source's concept may have no name, whichever write.
  • Accepted as edge cases, with reasons on the tracking ticket: contrived code spellings (a literal percent escape beside the code it decodes to), versionsMatch across two releases that reserve one code, a case setting that differs between releases, and supplements declared by a stored collection, which nothing sets yet.

🤖 Generated with Claude Code

https://claude.ai/code/session_01AaZ4qWapJWFsFc1Xjopf9k

paynejd and others added 6 commits December 1, 2026 08:06
…ply, one merged view of a concept, what an expansion used

Under FHIR's rules only (ExpansionEvaluation.fhir_rules); API users see no change.

- core.sources.supplements: a code system version's supplements, found by its canonical URL (the source_supplements_base
  index) and by pins (never HEAD; wildcards allowed); the versions a supplement applies to; one merged view of a
  concept (names, descriptions and extras, each marked with the supplement that gave it; the code system's own first),
  matching codes as written, then as FHIR spells them
- ExpansionEvaluation: supplements named by a request, declared by a collection version, then applied by default;
  supplements_for, merged, and require_applied, which raises SupplementNotFound with one message for a supplement
  unknown, hidden, not a supplement, or applying to none of the versions used (a hidden default is left out silently)
- Expansion: supplements_used, recorded for each code system version it used, including those reached through imports
  (supplement_bases)
- concepts: a supplement's concept may have no name, and a name or description no language (ANY_LANGUAGE), only when
  the write allows it (ALLOWS_ANY_LANGUAGE); every other source keeps every rule
- sources: an API metadata edit keeps a supplement with no language as it is

require_applied takes named=False for a value set that the one answered for imports: its own declarations alone are
its.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qWapJWFsFc1Xjopf9k
…s supplements, and supplement properties in filters

Under FHIR's rules only (ExpansionEvaluation.fhir_rules), and only for sources with reserved code spaces or supplements
in use; API users see no change.

- core.sources.reserved_codes.locate: a code in one of a version's reserved code spaces (the whole code matching the
  pattern, on RE2; a pattern that doesn't compile reserves nothing), with its default display (the space's, else
  User-assigned), and its definition by the first extension-codes supplement in use that defines it. Only an
  extension-codes supplement defines codes, and only in its base's reserved spaces
- core.collections.reserved_members: the reserved codes an expansion holds that no concept defines
  (Expansion.reserved_codes): a code a reference lists; all of a version's, which it can't list (has_unlisted_members),
  for a reference to all of a code system, or, narrowed to codes, those of them in its spaces. A filter, cascade or
  value set never selects one; exclusions and versions follow member_versions; with versionsMatch true they rank with
  the concept members of the same code; a code held under any stored form is the concept, never also a reserved code
- CollectionReference: a filter on a property a supplement in use declares (named, declared or global) reads that
  supplement's values with the code system's own, as the merged concept has them: =, in, exists true and regex select a
  concept when either value meets them; not-in and exists false keep a concept only when neither has such a value

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qWapJWFsFc1Xjopf9k
…e storage migrations bound their lock waits) into fhir-452-c-core

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qWapJWFsFc1Xjopf9k
…ead as it is when a supplement may apply

Under FHIR's rules, an imported value set version's default expansion is read as it is only when nothing the importer
brings would change it (core.collections.imports). A code system supplement in play is one more such thing: a filter
on a property a supplement declares reads the supplement's values, which the default expansion, built without them,
didn't. So when a supplement may apply where the import is evaluated now (one the request names, one the imported
version declares, or one applied by default: ExpansionEvaluation.asks_supplements), the import is evaluated again,
condition (5) in the module's list. Nothing changes when no supplement is in play, nor under OCL's own rules.

Test: a named supplement, and one the imported version declares, evaluate a stale import again; OCL's rules read it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qWapJWFsFc1Xjopf9k
…en a supplement applies to a version it used

Condition (5) of core.collections.imports was any supplement in play; a global supplement of another code system a
request carries then evaluated every stored import again, slower, and from its references rather than its default
expansion. Now it's a supplement that applies, where the import is evaluated now, to a source version its default
expansion used (ExpansionEvaluation.supplements_for), read only when one may.

Test: a supplement of another code system reads the stored expansion; one of the code system it used, named or
declared, evaluates it again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qWapJWFsFc1Xjopf9k
…o fhir-452-c-core

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qWapJWFsFc1Xjopf9k
…o fhir-452-c-core

Takes #1094's new head, which brings in master
(#1089, #1109 and
#1106): REFERENCE_SEARCH_OPTIONS_TOGGLE is on in every
environment, as on master. Merged cleanly; no change to this branch's own
code.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qVQviVc1p6MQwqUUed
paynejd added a commit that referenced this pull request Dec 2, 2026
… fhir-452-b9-valueset

Takes #1104's new head, which brings in master
(#1089, #1109 and
#1106): REFERENCE_SEARCH_OPTIONS_TOGGLE is on in every
environment, as on master. Merged cleanly; no change to this branch's own
code.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qVQviVc1p6MQwqUUed

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant